package com.meow.action.front;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/html/visa/FrontContentAction/")
public class FrontContentAction {
	
	private static final long serialVersionUID = 6095370804319200990L;
	
	@Autowired
	private BasicDataSource ds;
	
	private Logger logger = Logger.getLogger(FrontContinentAction.class);
	
	@RequestMapping("showContent.action")
	public String showContent(HttpServletRequest request, HttpServletResponse response) {
		try {
			Connection conn = ds.getConnection();
			try {
				String tableName = request.getParameter("tableName");
				String id = request.getParameter("id");
				String sql = "select content from " + tableName + " where id=?";
				PreparedStatement pstmt = conn.prepareStatement(sql);
				pstmt.setInt(1, Integer.parseInt(id));
				ResultSet rs = pstmt.executeQuery();
				if(rs.next()) {
					String rsContent = rs.getString("content");
					request.setAttribute("content", rsContent);
				}
				rs.close();
				pstmt.close();
			}
			finally {
				conn.close();
			}
			return "/HTML/ContentPreview_new.jsp";
		}
		catch (Exception e) {
			logger.error("", e);
		}
		return "";
	}
}
